home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 13.8 KB | 465 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: Content.cpp
- // Release Version: $ ODF 2 $
- //
- // Author: Mary Boetcher
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "Bitmap.hpp"
-
- #include "Binding.k"
-
- #ifndef CONTENT_H
- #include "Content.h"
- #endif
-
- #ifndef PART_H
- #include "Part.h"
- #endif
-
- #ifndef SELECT_H
- #include "Select.h"
- #endif
-
- // ----- Part Layer -----
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWKIND_H
- #include "FWKind.h"
- #endif
-
- // ----- OS Layer -----
-
- #ifndef FWODMISC_H
- #include "FWODMisc.h"
- #endif
-
- #ifndef FWPICTUR_H
- #include "FWPictur.h"
- #endif
-
- #ifndef FWBARRAY_H
- #include "FWBArray.h"
- #endif
-
- #ifndef FWFILEAC_H
- #include "FWFileAc.h"
- #endif
-
- #ifndef SLMixOS_H
- #include "SLMixOS.h"
- #endif
-
- #ifndef FWFILESY_H
- #include "FWFileSy.h"
- #endif
-
- #ifndef FWFILREP_H
- #include "FWFilRep.h"
- #endif
-
- // ----- Foundation Layer -----
-
- #ifndef FWSTREAM_H
- #include "FWStream.h"
- #endif
-
- #ifndef FWMEMORY_H
- #include "FWMemory.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.xh>
- #endif
-
- #ifndef SOM_ODTranslation_xh
- #include <Translt.xh>
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #include "odfjpeg.h"
-
- //========================================================================================
- // Runtime Information
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment odfbitmap
- #endif
-
- //========================================================================================
- // class CBitmapContent
- //========================================================================================
-
- FW_DEFINE_AUTO(CBitmapContent)
-
- //----------------------------------------------------------------------------------------
- // CBitmapContent::CBitmapContent
- //----------------------------------------------------------------------------------------
- // CBitmapContent constructor
-
- CBitmapContent::CBitmapContent(Environment* ev, CBitmapPart* part) :
- FW_CContent(ev, part),
- fBitmapPart(part)
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // CBitmapContent::~CBitmapContent
- //----------------------------------------------------------------------------------------
- // CBitmapContent destructor
-
- CBitmapContent::~CBitmapContent()
- {
- FW_START_DESTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // CBitmapContent::GetBitmap
- //----------------------------------------------------------------------------------------
-
- FW_CBitmap CBitmapContent::GetBitmap(Environment* ev) const
- {
- if ((const void*)fBitmap == NULL)
- {
- // Fool the compiler so we can do caching
- CBitmapContent* self = (CBitmapContent*)this;
- self->UseDefaultBitmap(ev);
- }
-
- return fBitmap;
- }
-
- //---------------------------------------------------------------------------------------
- // CBitmapContent::SetBitmap
- //---------------------------------------------------------------------------------------
-
- void CBitmapContent::SetBitmap (Environment* ev, FW_CBitmap bitmap)
- {
- FW_UNUSED(ev);
- fBitmap = bitmap;
- }
-
- //----------------------------------------------------------------------------------------
- // CBitmapContent::UseDefaultBitmap
- //----------------------------------------------------------------------------------------
- void CBitmapContent::UseDefaultBitmap(Environment* ev)
- {
- FW_PSharedLibraryResourceFile resFile(ev);
-
- #ifdef FW_BUILD_MAC
- FW_CPicture picture(resFile, 2128);
- fBitmap = FW_CBitmap(picture);
- #endif
- #ifdef FW_BUILD_WIN
- fBitmap = FW_CBitmap(resFile, 2128);
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // CBitmapContent::DoExternalize
- //----------------------------------------------------------------------------------------
-
- void CBitmapContent::DoExternalize(Environment* ev,
- ODStorageUnit* storageUnit,
- FW_CKind* kind,
- FW_CBitmap bitmap)
- {
- storageUnit->Focus(ev, kODPropContents, kODPosUndefined, kind->GetType(ev), 0, kODPosUndefined);
- FW_SUClearValue(ev, storageUnit, kODPropContents, kind->GetType(ev));
-
- // To test if fBitmap is NULL, cast it to a const void*
- if ((const void*)fBitmap != NULL)
- {
- FW_PStorageUnitSink suSink(ev, storageUnit, kODPropContents, kind->GetType(ev));
- FW_CWritableStream stream(suSink);
-
- if (kind->IsPartKind(ev))
- stream << bitmap;
- else if (kind->IsEqual(ev, kPICTOSType, kODPlatformDataType))
- ExternalizePICTData(ev, stream, bitmap);
- else
- FW_DEBUG_MESSAGE("CBitmapContent::DoExternalize - Unknown type");
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CBitmapContent::ExternalizeKind
- //----------------------------------------------------------------------------------------
- // ODF method
-
- void CBitmapContent::ExternalizeKind(Environment* ev,
- ODStorageUnit* storageUnit,
- FW_CKind* kind,
- FW_StorageKinds storageKind,
- FW_CPromise* promise,
- FW_CCloneInfo* cloneInfo)
- {
- FW_UNUSED(storageKind);
- FW_UNUSED(cloneInfo);
- FW_UNUSED(promise);
-
- DoExternalize(ev, storageUnit, kind, fBitmap);
- }
-
- #ifdef FW_BUILD_MAC
- //---------------------------------------------------------------------------------------
- // CBitmapContent::ExternalizePICTData
- //---------------------------------------------------------------------------------------
-
- void CBitmapContent::ExternalizePICTData(Environment* ev, FW_CWritableStream& stream, const FW_CBitmap& bitmap)
- {
- FW_UNUSED(ev);
- FW_CPicture picture = bitmap.MacGetAsPicture();
-
- FW_PlatformPict platformPict = picture.GetPlatformPict();
-
- unsigned long pictSize = FW_CMemoryManager::GetSystemHandleSize((FW_PlatformHandle)platformPict);
-
- FW_CAcquireLockedSystemHandle lockedHandle((FW_PlatformHandle)platformPict);
- stream.Write(lockedHandle.GetPointer(), pictSize);
- }
- #endif
-
- //----------------------------------------------------------------------------------------
- // CBitmapContent::InternalizeKind
- //----------------------------------------------------------------------------------------
- // ODF method
-
- FW_Boolean CBitmapContent::InternalizeKind(Environment* ev,
- ODStorageUnit* storageUnit,
- FW_CKind* kind,
- FW_StorageKinds storageKind,
- FW_CCloneInfo* cloneInfo)
- {
- FW_UNUSED(storageKind);
- FW_UNUSED(cloneInfo);
- if (kind->IsPartKind(ev)) {
- InternalizeBitmapShape(ev, storageUnit, kind);
- }
- else if (kind->IsEqual(ev, kPICTOSType, kODPlatformDataType)) {
- InternalizePICTData(ev, storageUnit, kind);
- }
- else if (kind->IsEqual(ev, kPICTOSType, kODPlatformFileType)) {
- InternalizePICTFile(ev, storageUnit);
- }
- else if (kind->IsEqual(ev, kJPEGOSType, kODPlatformDataType) ||
- kind->IsEqual(ev, kJFIFOSType, kODPlatformDataType)) {
- FW_PStorageUnitSink sink (ev, storageUnit, kODPropContents, kind->GetType(ev));
- FW_CBitmap bitmap = ODF_JPEG_Read (ev, sink);
- SetBitmap (ev, bitmap);
- }
- else if (kind->IsEqual(ev, kJPEGOSType, kODPlatformFileType) ||
- kind->IsEqual(ev, kJFIFOSType, kODPlatformFileType)) {
- FW_PFileValueSink sink(ev, storageUnit);
- FW_CBitmap bitmap = ODF_JPEG_Read (ev, sink);
- SetBitmap (ev, bitmap);
- }
- else
- {
- FW_DEBUG_MESSAGE("CBitmapContent::InternalizeKind - Unknown type");
- return false;
- }
-
- return true;
- }
-
- //---------------------------------------------------------------------------------------
- // CBitmapContent::InternalizeBitmapShape
- //---------------------------------------------------------------------------------------
-
- void CBitmapContent::InternalizeBitmapShape(Environment* ev, ODStorageUnit* storageUnit, FW_CKind* kind)
- {
- FW_PStorageUnitSink suSink(ev, storageUnit, kODPropContents, kind->GetType(ev));
- if (suSink->GetReadableBytes(ev) != 0)
- {
- FW_PBufferedSink sink(ev, suSink);
- FW_CReadableStream stream(sink);
- stream >> fBitmap;
- }
- }
-
- #ifdef FW_BUILD_MAC
- //---------------------------------------------------------------------------------------
- // CBitmapContent::InternalizePICTData
- //---------------------------------------------------------------------------------------
-
- void CBitmapContent::InternalizePICTData(Environment* ev, ODStorageUnit* storageUnit, FW_CKind* kind)
- {
- FW_PStorageUnitSink suSink(ev, storageUnit, kODPropContents, kind->GetType(ev));
- FW_PBufferedSink sink(ev, suSink);
- FW_CReadableStream stream(sink);
-
- unsigned long pictSize = storageUnit->GetSize(ev); //sink.GetLength();
-
- FW_CAcquireTemporarySystemHandle handle(pictSize);
-
- stream.Read(handle.GetPointer(), pictSize);
-
- MacSetBitmap(ev, (FW_PlatformPict)handle.GetPlatformHandle());
- }
- #endif
-
- #ifdef FW_BUILD_MAC
- //---------------------------------------------------------------------------------------
- // CBitmapContent::InternalizePICTFile
- //---------------------------------------------------------------------------------------
-
- void CBitmapContent::InternalizePICTFile(Environment* ev, ODStorageUnit* storageUnit)
- {
- HFSFlavor hfsInfo;
- if (FW_MacSUReadHFSFlavor(ev, storageUnit, kODPropContents, hfsInfo))
- {
- // Use the FileSpec in HFS flavor to open the file's data fork
- FW_PFileSpecification fileSpec(ev, hfsInfo.fileSpec);
- FW_CAccessPermission permission(FW_kRead, FW_kDenyWrite);
- FW_PFile pictFile(ev, fileSpec, permission);
- FW_PFileSink pictSink(ev, pictFile);
-
- // Read the picture data from the file
- #define kPICTHeaderSize 512
- unsigned long pictSize = pictSink->GetLength(ev) - kPICTHeaderSize;
-
- FW_CAcquireTemporarySystemHandle tempHandle(pictSize);
-
- pictSink->SetPosition(ev, kPICTHeaderSize); // skip PICT file header
- pictSink->Read(ev, tempHandle.GetPointer(), pictSize);
-
- MacSetBitmap(ev, (FW_PlatformPict)tempHandle.GetPlatformHandle());
- }
- }
- #endif
-
- #ifdef FW_BUILD_MAC
- //----------------------------------------------------------------------------------------
- // CBitmapContent::MacSetBitmap
- //----------------------------------------------------------------------------------------
- // Set the bitmap from from a pict handle. The FW_PlatformPict should be deleted by the
- // caller
-
- void CBitmapContent::MacSetBitmap(Environment* ev, FW_PlatformPict picHandle)
- {
- FW_UNUSED(ev);
- FW_CPicture picture(picHandle); // Does not take ownership
- fBitmap = FW_CBitmap(picture);
- }
- #endif
-
- //========================================================================================
- // class CBitmapSelectionContent
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CBitmapSelectionContent::CBitmapSelectionContent
- //----------------------------------------------------------------------------------------
- // CBitmapSelectionContent constructor
-
- CBitmapSelectionContent::CBitmapSelectionContent(Environment* ev, CBitmapPart* part, CBitmapSelection* selection, CBitmapContent* bitmapContent) :
- FW_CContent(ev, part),
- fBitmapPart(part),
- fBitmapContent(bitmapContent),
- fBitmapSelection(selection)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CBitmapSelectionContent::~CBitmapSelectionContent
- //----------------------------------------------------------------------------------------
- // CBitmapSelectionContent destructor
-
- CBitmapSelectionContent::~CBitmapSelectionContent()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CBitmapSelectionContent::SelectEntireBitmap
- //----------------------------------------------------------------------------------------
-
- void CBitmapSelectionContent::SelectEntireBitmap(Environment* ev)
- {
- short width, height,rowBytes, pixelSize;
- fBitmapContent->GetBitmap(ev).GetBitmapInfo(width, height, rowBytes, pixelSize);
- FW_CPlatformRect bounds(0, 0, width, height);
- SetSelectRect(bounds);
- }
-
- //----------------------------------------------------------------------------------------
- // CBitmapSelectionContent::InternalizeKind
- //----------------------------------------------------------------------------------------
- // ODF method
-
- FW_Boolean CBitmapSelectionContent::InternalizeKind(Environment* ev,
- ODStorageUnit* storageUnit,
- FW_CKind* kind,
- FW_StorageKinds storageKind,
- FW_CCloneInfo* cloneInfo)
- {
- fBitmapSelection->CloseSelection(ev);
-
- FW_Boolean result = fBitmapContent->InternalizeKind(ev, storageUnit, kind, storageKind, cloneInfo);
-
- if (result)
- {
- fBitmapPart->AdjustFramesSize(ev);
- fBitmapPart->UpdatePresentation(ev);
- }
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // CBitmapSelectionContent::ExternalizeKind
- //----------------------------------------------------------------------------------------
- // ODF method
-
- void CBitmapSelectionContent::ExternalizeKind(Environment* ev,
- ODStorageUnit* destinationSU,
- FW_CKind* kind,
- FW_StorageKinds storageKind,
- FW_CPromise* promise,
- FW_CCloneInfo* cloneInfo)
- {
- FW_UNUSED(storageKind);
- FW_UNUSED(cloneInfo);
- FW_UNUSED(promise);
-
- FW_CBitmap bitmap = fBitmapContent->GetBitmap(ev).Copy(fSelectRect);
-
- fBitmapContent->DoExternalize(ev, destinationSU, kind, bitmap);
- }
-
- //---------------------------------------------------------------------------------------
- // CBitmapSelectionContent::AcquireSuggestedFrameShape
- //---------------------------------------------------------------------------------------
- // Return the shape of the selected data. This will be added to the clipboard or
- // drag and drop storage unit.
-
- ODShape* CBitmapSelectionContent::AcquireSuggestedFrameShape(Environment* ev)
- {
- ODShape* shape = NULL;
-
- // ----- we don't use the zoom factor -----
- FW_CRect rect(fSelectRect);
- if (rect != FW_kZeroRect)
- {
- rect.Offset(-rect.left, -rect.top);
- shape = ::FW_NewODShape(ev, rect);
- }
-
- return shape;
- }
-
-